package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Compensationinfo;
import cn.wolfcode.crm.query.CompensationInfoQueryObject;
import cn.wolfcode.crm.service.ICompensationInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("compensationInfo")
public class CompensationInfoController {
    @Autowired
    private ICompensationInfoService compensationInfoService;

    @RequestMapping("view")
    public String view()
    {
        return "compensationInfo";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(CompensationInfoQueryObject qo) {
        return this.compensationInfoService.query(qo);
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Compensationinfo entity) {
        System.out.println(entity.getAmount());
        JsonResult result = new JsonResult();
        try {
            if (entity.getId() == null)
                this.compensationInfoService.insert(entity);
            else
                this.compensationInfoService.updateByPrimaryKey(entity);

        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }

        return result;
    }



    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll()
    {
        return this.compensationInfoService.selectAll();
    }

    @RequestMapping("selectByAid")
    @ResponseBody
    public Compensationinfo selectByAid(Long aid) {
        return this.compensationInfoService.selectByAid(aid);
    }

    @RequestMapping("deleteByPrimaryKey")
    @ResponseBody
    public JsonResult deleteByPrimaryKey(Long id) {
        JsonResult result = new JsonResult();
        try {
            this.compensationInfoService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }
}
